var app = {};
var rs = require('../module/respond');

app.isLogin = function (req,res,next) {
    var list = rs.copy(rs);
    if(req.session['uid']){
        next();
    }else{
        list.fail.returnCode = '401';
        list.fail.msg = '用户授权失败';
        res.send(list.fail);
    }
}

app.limit = function (req,res,next) {
    var list = rs.copy(rs);
    if(req.session['type'] == 0){
        next();
    }else{
        list.fail.msg = '您的账号已经被禁用';
        res.send(list.fail);
    }
}

app.permission = function (req,res,next) {
    var list = rs.copy(rs);
    if(req.session['type'] == 2 || req.session['type'] == 3){
        next();
    }else{
        list.fail.msg = '您没有权限';
        res.send(list.fail);
    }
}

app.higherPermission = function (req,res,next) {
    var list = rs.copy(rs);
    if(req.session['type'] == 3){
        next();
    }else{
        list.fail.msg = '您的权限不足';
        res.send(list.fail);
    }
}

module.exports = app;